<?php

namespace App\Admin\Controllers\Goods;

use App\Models\Goods\Goods;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;


class ExamineController extends Controller
{
    use ModelForm;
    protected $header = '商品审核';

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header($this->header);
            $content->description('description');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header($this->header);
            $content->description('description');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Goods::class, function (Grid $grid) {

            $grid->model()->where('to_examine','2');
            $grid->id('编号')->sortable();
            $grid->goods_icon('图片')->image('','50','50');
            $grid->goods_name('商品名称');
            $grid->money('价格');
            $grid->status('上架')->display(function ($status){
                return $status == 1 ? '是' : '否';
            });
            $grid->goods_recommend('推荐')->display(function ($goods_recommend){
                return $goods_recommend == 1 ? '是' : '否';
            });
            $grid->to_examine('审核状态')->display(function ($to_examine){
                return $to_examine == 1 ? '已审核' : '未审核';
            });

            //禁用创建按钮
            $grid->disableCreateButton();

            //搜索栏
            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('goods_name','商品名称');
            });

            //操作列
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                //禁用查看
                $actions->disableView();
                //禁用删除
                $actions->disableDelete();
            });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Goods::class, function (Form $form) {

            $form->tools(function (Form\Tools $tools) {
                // 去掉`删除`按钮
                $tools->disableDelete();
                // 去掉`查看`按钮
                $tools->disableView();
            });

            $form->footer(function ($footer) {
                // 去掉`查看`checkbox
                $footer->disableViewCheck();
                // 去掉`继续编辑`checkbox
                $footer->disableEditingCheck();
            });

            $form->display('id', '编号');
            $form->display('goods_name', '商品名称');
            $form->radio('to_examine','商品审核')->options([
                1 => '审核通过',
                2 => '审核不通过',
            ]);
            $form->textarea('goods_feedback','反馈详情');
        });
    }


}
